//---------------------------------------------------------------------------
// Name:	SimpleRequest.h
// Desc:	Header of CSimpleRequest
// Author:	D.C
// Date:	2007-09-04
//---------------------------------------------------------------------------

#ifndef _SIMPLE_REQUEST_
#define _SIMPLE_REQUEST_

#include "timer.h"
#include "cmeteor.h"

#define REQUEST_NONE -1
#define REQUEST_CONNECT 0
#define REQUEST_GET 1
#define REQUEST_POST 2

class MSimpleRequestObserver
{
public:
	virtual void ConnectComplete(TInt aCode)=0;
	virtual void SimpleRequestPos(TInt aBytes)=0;
	virtual void SimpleRequestFinish(const TDesC8& aBuf)=0;
	virtual void SimpleRequestError(TInt aCode)=0;
};

class CSimpleRequest:public CBase,public MMeteorNotifier,public MTimeOutNotifier
{
public:
	static CSimpleRequest* NewL();
	~CSimpleRequest();
public:
	void SetObserver(MSimpleRequestObserver* aObserver);
	TInt Connect(const TDesC& aHost,TInt aPort,TUint32 aIAP);
	void Disconnect();
	void Reset();
	TInt Get(const TDesC& aRequest);
	TInt Post(const TDesC& aRequest,const TDesC& aRequest2);
private:
	CSimpleRequest();
	void ConstructL();
private:
	void Request();
	TInt ParseResponseCode();
	TInt ParseFileType();
private:
	void TimerExpired();
private:
	virtual void ConnectionComplete(TInt aCode);
	virtual void DNSComplete(TInt aCode);
	virtual void SocketOpenComplete(TInt aCode);
	virtual void WriteBufferComplete(TInt aCode);
	virtual void ReadBufferComplete(TInt aCode,const TDesC8& aBuf);
	virtual void UnknowComplete(TInt aCode);

private:
	TMeteorFlag m_eFlag;
	CMeteor* m_pMeteor;
	CTimeOutTimer* m_pTimer;
	MSimpleRequestObserver* m_pObserver;
	HBufC8* m_pURL;
	HBufC8* m_pHost;
	TInt m_iPort;
	HBufC8* m_pLRL;
	TInt m_iIAP;

	TInt m_iResponseCode;
	HBufC8* m_pHeapBuf;
	HBufC8* m_pFileType;
	
	TInt iRequestType;
	HBufC8* iPostString;
};

#endif
